package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.constant.MemberTradeTypeEnum;
import com.ssy.lingxi.member.merchant.model.vo.comment.request.*;
import com.ssy.lingxi.member.merchant.model.vo.comment.response.MemberOrderCommentDetailVO;
import com.ssy.lingxi.member.merchant.model.vo.comment.response.MemberReceiveTradeCommentPageVO;
import com.ssy.lingxi.member.merchant.model.vo.comment.response.MemberSendTradeCommentPageVO;
import com.ssy.lingxi.member.merchant.model.vo.comment.response.MemberTradeCommentDetailVO;
import com.ssy.lingxi.member.merchant.model.vo.lifecycle.request.CommonIdVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.MemberDetailCreditCommentSummaryVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.MemberDetailCreditTradeHistoryVO;
import com.ssy.lingxi.member.merchant.service.base.IBaseMemberCacheService;
import com.ssy.lingxi.member.merchant.service.web.IMemberCommentService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 交易能力-会员评价接口
 * @author 万宁、姚梓聪
 * @version 2.0.0
 * @date 2020-10-23
 */
@RestController
@RequestMapping("/member/comment")
public class MemberCommentController {
    @Resource
    private IMemberCommentService memberCommentService;
    @Resource
    private IBaseMemberCacheService memberCacheService;

    // ====================采购会员========================

    /**
     * 交易能力-采购会员评价管理-交易评价汇总
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/count/trade/summary", method = RequestMethod.GET)
    public Wrapper<MemberDetailCreditCommentSummaryVO> getSubMemberTradeCommentSummary(@RequestHeader HttpHeaders headers) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.getSubMemberTradeCommentSummary(loginUser, MemberTradeTypeEnum.SELLER);
    }

    /**
     * 交易能力-采购会员评价管理-分页查询交易评论历史记录
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/count/trade/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberDetailCreditTradeHistoryVO>> pageMemberTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberHistoryPageVO pageVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.pageSubMemberTradeCommentHistory(loginUser, MemberTradeTypeEnum.SELLER, pageVO);
    }

    /**
     * 交易能力-采购会员评价管理-待评价订单-评价详情
     * @param headers Http头部信息
     * @param commonIdVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/order/trade/detail", method = RequestMethod.GET)
    public Wrapper<MemberOrderCommentDetailVO> getMemberOrderCommentDetail(@RequestHeader HttpHeaders headers, @Valid CommonIdVO commonIdVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.getMemberOrderCommentDetail(loginUser, MemberTradeTypeEnum.BUYER, commonIdVO);
    }

    /**
     * 交易能力-采购会员评价管理-待评价订单-发表评价
     * @param headers Http头部信息
     * @param memberTradeCommentSubmitVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/order/trade/submit", method = RequestMethod.POST)
    public Wrapper<Void> submitTradeComment(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberTradeCommentSubmitVO memberTradeCommentSubmitVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.submitMemberTradeComment(loginUser, MemberTradeTypeEnum.BUYER, memberTradeCommentSubmitVO);
    }

    /**
     * 交易能力-采购会员评价管理-收到评价-收到评价分页列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/receive/trade/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberReceiveTradeCommentPageVO>> pageReceiveMemberTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberReceiveTradeCommentQueryVO pageVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.pageMemberReceiveTradeCommentHistory(loginUser, MemberTradeTypeEnum.SELLER, pageVO);
    }

    /**
     * 交易能力-采购会员评价管理-收到评价-收到评价详情
     * @param headers Http头部信息
     * @param tradeCommentIdVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/receive/trade/history/get", method = RequestMethod.GET)
    public Wrapper<MemberTradeCommentDetailVO> getMemberReceivedTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberTradeCommentIdVO tradeCommentIdVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.getMemberTradeCommentHistory(loginUser, tradeCommentIdVO);
    }

    /**
     * 交易能力-采购会员评价管理-发出评价-发出评价分页列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/send/trade/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberSendTradeCommentPageVO>> pageMemberSendTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberSendTradeCommentQueryVO pageVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.pageMemberSendTradeCommentHistory(loginUser, MemberTradeTypeEnum.BUYER, pageVO);
    }

    /**
     * 交易能力-采购会员评价管理-发出评价-发出评价详情
     * @param headers Http头部信息
     * @param tradeCommentIdVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/send/trade/history/get", method = RequestMethod.GET)
    public Wrapper<MemberTradeCommentDetailVO> getMemberSendTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberTradeCommentIdVO tradeCommentIdVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.getMemberTradeCommentHistory(loginUser, tradeCommentIdVO);
    }

    /**
     * 交易能力-采购会员评价管理-发出评价-修改评价详情
     * @param headers Http头部信息
     * @param tradeCommentSubmitVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/consumer/send/trade/history/update", method = RequestMethod.POST)
    public Wrapper<Void> updateMemberTradeCommentHistory(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberTradeCommentUpdateDetail tradeCommentSubmitVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.updateMemberTradeCommentHistory(tradeCommentSubmitVO);
    }

    // ====================供应会员========================

    /**
     * 交易能力-供应会员评价管理-交易评价汇总
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/count/trade/summary", method = RequestMethod.GET)
    public Wrapper<MemberDetailCreditCommentSummaryVO> getSupplyMemberTradeCommentSummary(@RequestHeader HttpHeaders headers) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.getSubMemberTradeCommentSummary(loginUser, MemberTradeTypeEnum.BUYER);
    }

    /**
     *
     * 交易能力-供应会员评价管理-分页查询交易评论历史记录
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/count/trade/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberDetailCreditTradeHistoryVO>> pageSupplyMemberTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberHistoryPageVO pageVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.pageSubMemberTradeCommentHistory(loginUser, MemberTradeTypeEnum.BUYER, pageVO);
    }

    /**
     * 交易能力-供应会员评价管理-待评价订单-评价详情
     * @param headers Http头部信息
     * @param commonIdVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/order/trade/detail", method = RequestMethod.GET)
    public Wrapper<MemberOrderCommentDetailVO> getSupplyMemberOrderCommentDetail(@RequestHeader HttpHeaders headers, @Valid CommonIdVO commonIdVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.getMemberOrderCommentDetail(loginUser, MemberTradeTypeEnum.SELLER, commonIdVO);
    }

    /**
     * 交易能力-供应会员评价管理-待评价订单-发表评价
     * @param headers Http头部信息
     * @param memberTradeCommentSubmitVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/order/trade/submit", method = RequestMethod.POST)
    public Wrapper<Void> submitSupplyTradeComment(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberTradeCommentSubmitVO memberTradeCommentSubmitVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.submitMemberTradeComment(loginUser, MemberTradeTypeEnum.SELLER, memberTradeCommentSubmitVO);
    }

    /**
     * 交易能力-供会应员评价管理-收到评价-收到评价分页列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/receive/trade/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberReceiveTradeCommentPageVO>> pageSupplyReceiveMemberTradeCommentHistory(@RequestHeader HttpHeaders headers, MemberReceiveTradeCommentQueryVO pageVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.pageMemberReceiveTradeCommentHistory(loginUser, MemberTradeTypeEnum.BUYER, pageVO);
    }

    /**
     * 交易能力-供应会员评价管理-收到评价-解释回复
     * @param headers Http头部信息
     * @param memberTradeCommentSubmitVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/receive/trade/history/reply", method = RequestMethod.POST)
    public Wrapper<Void> replySupplyReceiveMemberTradeCommentHistory(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberTradeReceiveCommentReplyVO memberTradeCommentSubmitVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.replyReceiveMemberTradeCommentHistory(loginUser, memberTradeCommentSubmitVO);
    }

    /**
     * 交易能力-供应会员评价管理-收到评价-收到评价详情
     * @param headers Http头部信息
     * @param tradeCommentIdVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/receive/trade/history/get", method = RequestMethod.GET)
    public Wrapper<MemberTradeCommentDetailVO> getSupplyMemberReceivedTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberTradeCommentIdVO tradeCommentIdVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.getMemberTradeCommentHistory(loginUser, tradeCommentIdVO);
    }

    /**
     * 交易能力-供应会员评价管理-发出评价分页列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/send/trade/history/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberSendTradeCommentPageVO>> pageSupplyMemberSendTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberSendTradeCommentQueryVO pageVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.pageMemberSendTradeCommentHistory(loginUser, MemberTradeTypeEnum.SELLER, pageVO);
    }

    /**
     * 交易能力-供应会员评价管理-发出评价-发出评价详情
     * @param headers Http头部信息
     * @param tradeCommentIdVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/send/trade/history/get", method = RequestMethod.GET)
    public Wrapper<MemberTradeCommentDetailVO> getSupplyMemberSendTradeCommentHistory(@RequestHeader HttpHeaders headers, @Valid MemberTradeCommentIdVO tradeCommentIdVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.getMemberTradeCommentHistory(loginUser, tradeCommentIdVO);
    }

    /**
     * 交易能力-供应会员评价管理-发出评价-修改评价详情
     * @param headers Http头部信息
     * @param tradeCommentSubmitVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/send/trade/history/update", method = RequestMethod.POST)
    public Wrapper<Void> updateMemberSendTradeCommentHistory(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberTradeCommentUpdateDetail tradeCommentSubmitVO) {
        UserLoginCacheDTO loginUser = memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.updateMemberTradeCommentHistory(tradeCommentSubmitVO);
    }

    /**
     * 交易能力-供应会员评价管理-收到评价-修改是否显示商品评价
     * @param headers  Http头部信息
     * @param updateVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/supply/receive/show/evaluation/update", method = RequestMethod.POST)
    public Wrapper<Void> updateSupplyReceiveShowEvaluation(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberTradeCommentUpdateStatusVO updateVO) {
        memberCacheService.needLoginFromBusinessPlatform(headers);
        return memberCommentService.updateSupplyReceiveShowEvaluation(updateVO);
    }
}
